<template>
  <div class="article-list">
    <router-link v-for="(item, i) in data" :key="i" :to="`/detail/${item.id}`" class="article-item">
      <h2 class="item-title">{{ item.title }}</h2>
      <p class="item-desc plain">{{ item.brief }}</p>
      <div class="item-bottom">
        <time class="time">{{ formatTime(item.create_time) }}</time>
        <span class="item-tag">{{ item.tagName }}</span>
      </div>
    </router-link>
    <div class="pagination">
      <my-pagination v-bind="pData"></my-pagination>
    </div>
  </div>
</template>

<script>
import moment from 'moment'

import MyPagination from '../myPagination'

export default {
  props: {
    data: {
      type: Array,
      default() {
        return []
      }
    },
    pagination: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  computed: {
    pData() {
      return { ...this.pagination, page: (parseInt(this.$route.query.page) || 1) }
    },
  },
  methods: {
    formatTime(time) {
      if (moment(time).isBefore('2016-08-08', 'day')) {
        return `${(new Date()).getFullYear() - 2016}年以前`
      }
      return time
    }
  },
  components: {
    MyPagination
  }
}
</script>

<style scoped lang="scss">
.pagination {
  padding: 25px 0;
}
.article-item {
  background: white;
  padding: 20px 0;
  line-height: 1.3;
  display: block;
  border-bottom: 1px solid #dfdfdf;
  &:hover {
    text-decoration: none;
  }
}
.item-title {
  font-size: 24px;
  color: #333;
  line-height: 1.3;
  &:hover {
    text-decoration: underline;
  }
}
.item-desc {
  padding: 10px 0;
  font-size: 14px;
  color: #888;
  word-break: break-all;
}
.item-bottom {
  display: flex;
  align-items: center;
  font-size: 16px;
  justify-items: flex-end;
  color: #888;
  .time {
    padding-right: 20px;
  }
}

.item-tag {
  border: 1px solid #dfdfdf;
  padding: 2px 8px;
  color: #888;
}

@media screen and (max-width: 768px) {
  .item-title {
    font-size: 18px;
  }
  .item-desc {
    line-height: 1.2;
  }
  .item-bottom {
    font-size: 14px;
  }
}
</style>
